#include "aroundArea.h"
void areaDfs(std::vector<std::vector<char>> &board, int x, int y) {
    if (x < 0 || x > board.size() - 1 || y < 0 || y > board[0].size() - 1 ||
        board[x][y] != 'O') {
        return;
    } else {
        board[x][y] = 'A';
        areaDfs(board, x - 1, y);
        areaDfs(board, x + 1, y);
        areaDfs(board, x, y - 1);
        areaDfs(board, x, y + 1);
    }
}

void aroundArea(std::vector<std::vector<char>> &board) {
    int rows = board.size();
    int cols = board[0].size();
    for (int c = 0; c < cols; c++) {
        areaDfs(board, 0, c);
        areaDfs(board, rows - 1, c);
    }

    for (int r = 0; r < rows; r++) {
        areaDfs(board, r, 0);
        areaDfs(board, r, cols - 1);
    }
    for (int r = 0; r < board.size(); r++) {
        for (int c = 0; c < board[0].size(); c++) {
            if (board[r][c] == 'A') {
                board[r][c] = 'O';
            } else if (board[r][c] == 'O') {
                board[r][c] = 'X';
            }
        }
    }
}
